#coding=utf-8

import web
db = web.database(dbn='mysql', db='test', user='root',pw='******')

def get_emails():
    """获取收件箱邮件"""
    return db.query('select mailid,star,sender,subject,receivetime,filesize from emails where deleted=0')

def get_deletedemails():
    """获取回收站邮件"""
    return db.query('select mailid,star,sender,subject,receivetime,filesize from emails where deleted=1')
    
def delete_email(id):
    """删除状态改为1"""
    return db.update('emails', where="mailid = $id", vars = locals(), deleted = 1)

def star_email(id):
    """标星状态改为1"""
    return db.update('emails', where="mailid = $id", vars = locals(), star = 1) 
    
def unstar_email(id):
    """标星状态改为0"""
    return db.update('emails', where="mailid = $id", vars = locals(), star = 0) 
   
def get_emailpath(id):
    """获取文件目录"""
    return db.query('select filedir from emails where mailid = $id', vars={'id':id})
    
def get_email_content(id):
    """获取邮件内容"""
    return db.query('select content from emails where mailid = $id', vars={'id':id})


